package cz.zcu.fav.rat.managed.bean;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedProperty;

import cz.zcu.fav.rat.dataaccess.dao.GenericDAO;
import cz.zcu.fav.rat.dataaccess.service.GenericDataAccessService;

public abstract class AbstractViewItemBean<T, TT extends GenericDataAccessService<T, GenericDAO<T, Integer>>>
{

	private T selectedItem;

	@ManagedProperty(value = "#{param.id}")
	private Integer id;

	@PostConstruct
	public void init()
	{
		if (id != null && id >= 0)
		{
			selectedItem = getDataProvider().get(id);
		}
	}

	public T getSelectedItem()
	{
		return selectedItem;
	}

	public void setSelectedItem(T selectedItem)
	{
		this.selectedItem = selectedItem;
	}

	protected abstract TT getDataProvider();


	public void setId(Integer id)
	{
		this.id = id;
	}

	public Integer getId()
	{
		return id;
	}

}
